package student.aistar.service2.impl;


import student.aistar.dao2.IUserDao;
import student.aistar.dao2.IVideoDao;
import student.aistar.dao2.impl.UserDaoImpl;
import student.aistar.dao2.impl.VideoDaoImpl;
import student.aistar.model.dto.UserVo;
import student.aistar.model.pojo.User;
import student.aistar.model.pojo.Video;
import student.aistar.service2.IUseService;

import java.util.List;

public class UserServiceImpl implements IUseService {
    //service层调用dao层
    private IUserDao userDao = new UserDaoImpl();
    private IVideoDao videoDao = new VideoDaoImpl();
    @Override
    public UserVo loadById(Integer id) {
        UserVo userVo = new UserVo();
        //根据用户的id查询用户信息, 如果该用户具有视频信息加载出来
        //得到用户对象
        User user = userDao.findById(id);
        userVo.setUser(user);

        //得到这个用户的所有的视频信息
        List<Video> videoList = videoDao.findByUserId(id);
        //判断这个用户是否拥有视频信息
        if(null != videoList && videoList.size() > 0){
            userVo.setVideoList(videoList);
        }
        return userVo;
    }
}
